home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: alisa.org!wjjr
- From: wjjr@alisa.org (John J. Rushford)
- Subject: Re: routine for yesterday's date
- X-Newsreader: TIN [version 1.2 PL2]
- Organization: My place on the Front Range.
- Message-ID: <Dp3B56.FKI@alisa.org>
- References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com>
- Date: Sat, 30 Mar 1996 16:58:18 GMT
-
- Mark Brader (msb@sq.com) wrote:
- : Bruce Coghill (75323.455@compuserve.com) writes at 2:48 PM, March 29, 1996:
- :
- : > In my C manual the time.h and time functions are described
- : > and how I can pull off each element in the structure (like year,
- : > month, day, day-of-the-year), but it isn't clear to me how to subtract
- : > a day.
-
- : This is question 13.14 on the FAQ list, but I'd like to expand a bit
- : on what it says there.
-
- : Bruce, you have gotten as far as calling time() and localtime(). The
- : next thing is to use the normalizing feature of mktime(). Suppose that
- : you have a variable of type struct tm called x, and you've just put the
- : current time into it using localtime(). Now you basically just want to
- : do something like this:
-
- : x.tm_day--; /* back 1 day */
- : (void) mktime (&x); /* normalize */
-
- [stuff deleted]
-
- Why bother with mktime() when it is so much easier to use the following and
- you don't have to bother with errors gotten from x.tm_day--;
-
- long ticks
- struct tm * dt;
-
- time(&ticks);
-
- /* 86400 seconds in a day */
- ticks -= 86400
-
- dt = localtime (&ticks);
-
- regards
- --
- John J. Rushford
- Westminster, Colorado___/\_/\_
- wjjr@alisa.org (alisa.org is powered by FreeBSD)
-
-